package com.example.demo.ai;


import io.a2a.client.A2ACardResolver;
import io.a2a.client.A2AClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiClient {
    private final ChatClient chatClient;

    public AiClient(ChatClient.Builder builder, ElasticsearchVectorStore vectorStore) {
        this.chatClient = builder.defaultAdvisors(new QuestionAnswerAdvisor(vectorStore)).build();
    }


    @RequestMapping("/client/demo")
    public String test(){
        // Create an A2AClient (the URL specified is the server agent's URL, be sure to replace it with the actual URL of the A2A server you want to connect to)
        A2AClient client = new A2AClient("http://localhost:1234");
        long begin=System.currentTimeMillis();
        String message="请详细描述下，列举数学问题的实际应用场景";
        String result= chatClient.prompt(message).call().content();
        System.out.println("cost:"+(System.currentTimeMillis()-begin));
        return result;
    }
}
